package com.room.reservation.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.room.common.annotation.Log;
import com.room.common.core.controller.BaseController;
import com.room.common.core.domain.AjaxResult;
import com.room.common.enums.BusinessType;
import com.room.reservation.domain.RoomReservation;
import com.room.reservation.service.IRoomReservationService;
import com.room.common.utils.poi.ExcelUtil;
import com.room.common.core.page.TableDataInfo;

/**
 * 自习室预约管理Controller
 * 
 * @author FMBOY
 * @date 2025-11-16
 */
@RestController
@RequestMapping("/reservation/reservation")
public class RoomReservationController extends BaseController
{
    @Autowired
    private IRoomReservationService roomReservationService;

    /**
     * 查询自习室预约管理列表
     */
    @PreAuthorize("@ss.hasPermi('reservation:reservation:list')")
    @GetMapping("/list")
    public TableDataInfo list(RoomReservation roomReservation)
    {
        startPage();
        List<RoomReservation> list = roomReservationService.selectRoomReservationList(roomReservation);
        return getDataTable(list);
    }

    /**
     * 导出自习室预约管理列表
     */
    @PreAuthorize("@ss.hasPermi('reservation:reservation:export')")
    @Log(title = "自习室预约管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RoomReservation roomReservation)
    {
        List<RoomReservation> list = roomReservationService.selectRoomReservationList(roomReservation);
        ExcelUtil<RoomReservation> util = new ExcelUtil<RoomReservation>(RoomReservation.class);
        util.exportExcel(response, list, "自习室预约管理数据");
    }

    /**
     * 获取自习室预约管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('reservation:reservation:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(roomReservationService.selectRoomReservationById(id));
    }

    /**
     * 新增自习室预约管理
     */
    @PreAuthorize("@ss.hasPermi('reservation:reservation:add')")
    @Log(title = "自习室预约管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RoomReservation roomReservation)
    {
        return toAjax(roomReservationService.insertRoomReservation(roomReservation));
    }

    /**
     * 修改自习室预约管理
     */
    @PreAuthorize("@ss.hasPermi('reservation:reservation:edit')")
    @Log(title = "自习室预约管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RoomReservation roomReservation)
    {
        return toAjax(roomReservationService.updateRoomReservation(roomReservation));
    }

    /**
     * 删除自习室预约管理
     */
    @PreAuthorize("@ss.hasPermi('reservation:reservation:remove')")
    @Log(title = "自习室预约管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(roomReservationService.deleteRoomReservationByIds(ids));
    }
}
